<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props使用</title>
</head>
<body>
  <!-- 准备容器 -->
  <div id="test"></div>
  <div id="test1"></div>
  <!-- 按照顺序引入 -->
  <script type="text/javascript" src="../../js/react.development.js"></script>
  <script type="text/javascript" src="../../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../../js/babel.min.js"></script>
  <!-- 引入prop-types用于对组件标签属性进行限制 -->
  <script type="text/javascript" src="../../js/prop-types.js"></script>
  <script type="text/babel" >
    class Person extends React.Component {
      render () { 
        // props是只读的  不能修改  this.props.name='jack'会报错
        const {name,age,sex} = this.props
        return (
          <ul>
              <li>姓名：{name}</li>
              <li>性别：{sex}</li>
              <li>年龄：{age+1}</li>
          </ul>
        )
      }
    }
    // Person.属性规则 ={name:'必传，字符串'}
    Person.propTypes = {
      name:PropTypes.string.isRequired,
      sex:PropTypes.string,
      age:PropTypes.number,
      speak:PropTypes.func // 限制为函数
    }
    Person.defaultProps={
      sex:'人妖',
      age:18
    }
    ReactDOM.render(<Person speak={speak} name='tom' sex='男' age={18}/>,document.getElementById('test'))
    const p ={ name:'jerry' ,sex:'女', age:16}
    // ReactDOM.render(<Person name='jerry' sex='女' age='16'/>,document.getElementById('test1'))
    // ReactDOM.render(<Person name={p.name} sex={p.sex} age={p.age}/>,document.getElementById('test1'))
    // console.log('p',...p);// ...运算符只适用于标签使用  直接打印...p为空
    ReactDOM.render(<Person {...p}/>,document.getElementById('test1'))
    function speak(){
      console.log('哈哈哈');
    }
  </script>
</body>
</html>